from typing import Optional, List

from fastapi import APIRouter
from starlette.requests import Request

from schemas import Response
from schemas.area import AreaOutSchema, AreaSubSchema
from service.area import AreaService
area = APIRouter(tags=['省市区'])

__all__ = ["area"]

ResponseList = Response[Optional[List[AreaOutSchema]]]
ResponseArea = Response[Optional[AreaSubSchema]]


@area.get("/area", summary='获取所有一级', response_model=ResponseList)
async def get_all_parents(request: Request):
    """所有省"""
    return await AreaService.get_parents(request)


@area.get("/area/{pk}", summary='获取二级', response_model=ResponseArea)
async def get_area(pk: int, request: Request):
    """获取省下"""
    return await AreaService.get_area(request, pk)
